package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.OutStockDetailVO;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/business/outStock")
public class OutStockController {

    @Autowired
    private OutStockService outStockService;

    //出库单（发放记录）数据分页列表展示
    @GetMapping("/findOutStockList")
    public ResponseBean<PageVO<OutStockVO>> findOutStockList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                                             Integer status,
                                                             String outNum,
                                                             Integer type){

        PageVO<OutStockVO> pageVO = outStockService.findOutStockList(pageNum,pageSize,status,outNum,type);
        return ResponseBean.success(pageVO);
    }

    //物资明细列表
    @GetMapping("/detail/{id}")
    public ResponseBean detailOutStock(@PathVariable Long id,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "3") Integer pageSize){
        OutStockDetailVO outStockDetailVO = outStockService.detailOutStock(id,pageNum,pageSize);
        return ResponseBean.success(outStockDetailVO);
    }

    //将出库单移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean removeOutStock(@PathVariable Long id){
        outStockService.removeOutStock(id);
        return ResponseBean.success();
    }

    //将回收站的出库单还原
    @PutMapping("/back/{id}")
    public ResponseBean backOutStock(@PathVariable Long id){
        outStockService.backOutStock(id);
        return ResponseBean.success();
    }

    //删除出库单
    @GetMapping("/delete/{id}")
    public ResponseBean deleteOutStock(@PathVariable Long id){
        outStockService.deleteOutStock(id);
        return ResponseBean.success();
    }

    //添加出库单（发放物资）
    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody Map<String,Object> map){
        outStockService.addOutStock(map);
        return ResponseBean.success();
    }

    //出库单（发放物资）审核
    @PutMapping("/publish/{id}")
    public ResponseBean publishOutStock(@PathVariable Long id){
        //更改审核状态
        outStockService.publishOutStock(id);
        //更新库存数量
        outStockService.lessProductStock(id);
        return ResponseBean.success();
    }
}
